<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录界面</title>
    <link rel="stylesheet" href="new/css/auth.css">
</head>

<body>
<div class="lowin">
    <div class="lowin-brand">
        <img src="new/images/kodinger.jpg" alt="logo">
    </div>
    <div class="lowin-wrapper">
        <div class="lowin-box lowin-login">
            <div class="lowin-box-inner">
                <div >
                    <p>登录页面</p>
                    <div class="lowin-group">
                        <label>邮箱账户</label>
                        <input type="email" autocomplete="email" id="email" name="email" class="lowin-input">
                    </div>
                    <div class="lowin-group password-group">
                        <label>密码 </label>
                        <input type="password" name="password" id="password" autocomplete="current-password" class="lowin-input">
                    </div>
                    <button class="lowin-btn login-btn" onclick="subLogin()">
                        登录
                    </button>
                    <div class="text-foot">
                        Don't have an account? <a href="register.html" class="register-link">注册</a>
                    </div>
                </div>
            </div>
        </div>
        </div>
    </div>

    <footer class="lowin-footer">
        Copyright &copy; 2020.From graduation project.
    </footer>
</div>

<script src="https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
<script>
    function subLogin(){
        var email = $("#email").val();	  //账号
        var pwd = $("#password").val();	//密码
        if (email.length <= 0){
            layer.msg("账号不为空!",{icon:2,time:2000});
            return false;
        }
        if (pwd.length <= 0){
            layer.msg("密码不为空!",{icon:2,time:2000});
            return false;
        }
        var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
        if(!reg.test(email)){
            layer.msg("账户格式不正确!应该为邮箱格式",{icon:2,time:2000});
            return false;
        }
        var user={"account":email,"pwd":pwd,"type":1};
        $.ajax({
            url : "/user/login",
            type : "POST",
            contentType : 'application/json',
            dataType : 'json',
            data :JSON.stringify(user),
            success : function(json) {
                if(json.result == true){
                    layer.msg("登录成功",{icon:1,time:2000},function () {
                        window.localStorage.setItem("userId",json.data.id);
                        window.localStorage.setItem("nickName",json.data.nickName);
                        window.localStorage.setItem("isLogin", true);
                        location.href="index.html";
                    });
                }else{
                    layer.msg(json.message,{icon:2,time:1500});
                }
            }
        });
    };//点击登陆
</script>
</body>
</html>
